home *** CD-ROM | disk | FTP | other *** search
- /**
- * Scout - The Amiga System Monitor
- *
- *------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * You must not use this source code to gain profit of any kind!
- *
- *------------------------------------------------------------------
- *
- * @author Andreas Gelhausen
- * @author Richard Körber <rkoerber@gmx.de>
- */
-
- #include "system_headers.h"
-
- struct WindowsCallbackUserData {
- APTR ud_Tree;
- ULONG ud_Count;
- };
-
- static __asm __saveds LONG wintree_confunc(register __a2 Object *obj, register __a1 struct MUIP_NListtree_ConstructMessage *msg, register __a0 struct Hook *hook)
- {
- return AllocListEntry(msg->MemPool, msg->UserData, sizeof(struct WindowEntry));
- }
-
- MakeHook(wintree_conhook, wintree_confunc);
-
- static __asm __saveds LONG wintree_desfunc(register __a2 Object *obj, register __a1 struct MUIP_NListtree_ConstructMessage *msg, register __a0 struct Hook *hook)
- {
- FreeListEntry(msg->MemPool, &msg->UserData);
-
- return 0;
- }
-
- MakeHook(wintree_deshook, wintree_desfunc);
-
- static __asm __saveds LONG wintree_dspfunc(register __a2 Object *obj, register __a1 struct MUIP_NListtree_DisplayMessage *msg, register __a0 struct Hook *hook)
- {
- static UBYTE *empty="\0";
-
- if (msg->TreeNode != NULL) {
- struct WindowEntry *we = msg->TreeNode->tn_User;
-
- if (stricmp(we->we_Type, "SCREEN") == 0) {
- msg->Array[0] = we->we_Address;
- msg->Array[1] = we->we_Position;
- msg->Array[2] = we->we_Size;
- msg->Array[3] = we->we_Flags;
- msg->Array[4] = empty;
- msg->Array[5] = we->we_Title;
- msg->Preparse[0] = MUIX_PH;
- msg->Preparse[1] = MUIX_PH;
- msg->Preparse[2] = MUIX_PH;
- msg->Preparse[3] = MUIX_PH;
- msg->Preparse[4] = MUIX_PH;
- msg->Preparse[5] = MUIX_PH;
- } else if (stricmp(we->we_Type, "WINDOW") == 0) {
- msg->Array[0] = we->we_Address;
- msg->Array[1] = we->we_Position;
- msg->Array[2] = we->we_Size;
- msg->Array[3] = we->we_Flags;
- msg->Array[4] = we->we_IDCMP;
- msg->Array[5] = we->we_Title;
- }
- } else {
- msg->Array[0] = "Address";
- msg->Array[1] = "Pos(x,y)";
- msg->Array[2] = "Size(w,h)";
- msg->Array[3] = "Flags";
- msg->Array[4] = "IDCMP";
- msg->Array[5] = "Title";
- msg->Preparse[0] = MUIX_B;
- msg->Preparse[1] = MUIX_B;
- msg->Preparse[2] = MUIX_B;
- msg->Preparse[3] = MUIX_B;
- msg->Preparse[4] = MUIX_B;
- msg->Preparse[5] = MUIX_B;
- }
-
- return 0;
- }
-
- MakeHook(wintree_dsphook, wintree_dspfunc);
-
- static __asm __saveds LONG wintree_findfunc(register __a2 Object *obj, register __a1 struct MUIP_NListtree_FindUserDataMessage *msg, register __a0 struct Hook *hook)
- {
- struct WindowEntry *we;
-
- we = (struct WindowEntry *)msg->UserData;
-
- if (we) {
- if (stricmp(we->we_Type, "SCREEN") == 0) {
- return stricmp((UBYTE *)msg->User, we->we_ScreenAddress);
- } else {
- return ~0;
- }
- } else {
- return ~0;
- }
- }
-
- MakeHook(wintree_findhook, wintree_findfunc);
-
- void CloseScreenAll( struct Screen *screen )
- {
- struct Window *win, *nextwin;
-
- win = screen->FirstWindow;
- while (win) {
- nextwin = win->NextWindow;
- CloseWindow(win);
- win = nextwin;
- }
- CloseScreen(screen);
- }
-
- static void ReceiveList( void (* callback)( struct WindowEntry *we, void *userData ),
- void *userData )
- {
- struct WindowEntry *we;
-
- if (we = tbAllocVecPooled(globalPool, sizeof(struct WindowEntry))) {
- if (SendDaemon("GetWinList")) {
- while (ReceiveDecodedEntry((UBYTE *)we, sizeof(struct WindowEntry))) {
- callback(we, userData);
- }
- }
-
- tbFreeVecPooled(globalPool, we);
- }
- }
-
- static void IterateList( void (* callback)( struct WindowEntry *we, void *userData ),
- void *userData )
- {
- struct MinList tmplist;
- struct WindowEntry *we, *_we;
- ULONG lock;
- struct Screen *screen;
-
- NewList((struct List *)&tmplist);
-
- lock = LockIBase(0);
-
- screen = FIRSTSCREEN;
-
- while (screen) {
- if (we = AllocVec(sizeof(struct WindowEntry), MEMF_PUBLIC)) {
- struct Window *window;
-
- we->we_Addr = (APTR)screen;
-
- _snprintf(we->we_Address, sizeof(we->we_Address), "$%08lx", screen);
- _snprintf(we->we_Position, sizeof(we->we_Position), "%4ld,%-4ld", screen->LeftEdge, screen->TopEdge);
- _snprintf(we->we_Size, sizeof(we->we_Size), "%4ld,%-4ld", screen->Width, screen->Height);
- _snprintf(we->we_Flags, sizeof(we->we_Flags), "$%04lx", screen->Flags);
- stccpy(we->we_IDCMP, "---------", sizeof(we->we_IDCMP));
- _snprintf(we->we_Title, sizeof(we->we_Title), "%-."TEXT_LENGTH_CHAR"s", nonetest(screen->Title));
- _snprintf(we->we_ScreenAddress, sizeof(we->we_ScreenAddress), "$%08lx", screen);
- stccpy(we->we_Type, "SCREEN", sizeof(we->we_Type));
-
- AddTail((struct List *)&tmplist, (struct Node *)we);
-
- if (window = screen->FirstWindow) {
- while (window) {
- if (we = AllocVec(sizeof(struct WindowEntry), MEMF_PUBLIC)) {
- we->we_Addr = (APTR)window;
- _snprintf(we->we_Address, sizeof(we->we_Address), "$%08lx", window);
- _snprintf(we->we_Position, sizeof(we->we_Position), "%4ld,%-4ld", window->LeftEdge, window->TopEdge);
- _snprintf(we->we_Size, sizeof(we->we_Size), "%4ld,%-4ld", window->Width, window->Height);
- _snprintf(we->we_Flags, sizeof(we->we_Flags), "$%08lx", window->Flags);
- _snprintf(we->we_IDCMP, sizeof(we->we_IDCMP), "$%08lx", window->IDCMPFlags);
- _snprintf(we->we_Title, sizeof(we->we_Title), "%-."TEXT_LENGTH_CHAR"s", nonetest(window->Title));
- _snprintf(we->we_ScreenAddress, sizeof(we->we_ScreenAddress), "$%08lx", screen);
- stccpy(we->we_Type, "WINDOW", sizeof(we->we_Type));
-
- AddTail((struct List *)&tmplist, (struct Node *)we);
- }
-
- window = window->NextWindow;
- }
- }
- }
-
- screen = screen->NextScreen;
- }
-
- UnlockIBase(lock);
-
- ITERATE_CHANGING_LIST(&tmplist, struct WindowEntry *, we, _we) {
- callback(we, userData);
- FreeVec(we);
- }
- }
-
- static void UpdateCallback( struct WindowEntry *we,
- void *userData )
- {
- struct WindowsCallbackUserData *ud = (struct WindowsCallbackUserData *)userData;
- struct MUI_NListtree_TreeNode *parent;
- ULONG flags;
-
- flags = 0;
- if (stricmp(we->we_Type, "SCREEN") == 0) flags = TNF_LIST | TNF_OPEN;
- if (stricmp(we->we_Type, "WINDOW") == 0) flags = 0;
-
- parent = (struct MUI_NListtree_TreeNode *)DoMethod(ud->ud_Tree, MUIM_NListtree_FindUserData, MUIV_NListtree_FindUserData_ListNode_Root, we->we_ScreenAddress, MUIV_NListtree_FindUserData_Flag_StartNode);
- DoMethod(ud->ud_Tree, MUIM_NListtree_Insert, we->we_Title, we, parent, MUIV_NListtree_Insert_PrevNode_Sorted, flags);
- ud->ud_Count++;
- }
-
- static void PrintCallback( struct WindowEntry *we,
- void *userData )
- {
- if (stricmp(we->we_Type, "SCREEN") == 0) {
- PrintFOneLine((BPTR)userData, " %s %s %s %-9.9s %s %-26.26s\n", we->we_Address, we->we_Position + 2, we->we_Size + 2, we->we_Flags + 2, we->we_IDCMP + 2, we->we_Title + 2);
- } else {
- PrintFOneLine((BPTR)userData, " %s %s %s %-9.9s %s %-26.26s\n", we->we_Address, we->we_Position, we->we_Size, we->we_Flags, we->we_IDCMP, we->we_Title);
- }
- }
-
- static void SendCallback( struct WindowEntry *we,
- void *userData )
- {
- SendEncodedEntry((UBYTE *)we, sizeof(struct WindowEntry));
- }
-
- static ULONG __saveds mNew( struct IClass *cl,
- Object *obj,
- struct opSet *msg )
- {
- APTR winlist, wintree, wintext, updateButton, printButton, closeButton, frontButton, moreButton, exitButton;
-
- if (obj = (Object *)DoSuperNew(cl, obj,
- MUIA_HelpNode, WindowsText,
- MUIA_Window_ID, MakeID('W','I','N','D'),
- WindowContents, VGroup,
-
- Child, winlist = MyNListtreeObject(&wintree, "BAR,BAR P=" MUIX_C ",BAR P=" MUIX_C ",BAR,BAR,BAR", &wintree_conhook, &wintree_deshook, &wintree_dsphook, NULL, &wintree_findhook, 5),
- Child, wintext = MyTextObject(),
-
- Child, MyVSpace(4),
-
- Child, HGroup, MUIA_Group_SameSize, TRUE,
- Child, updateButton = MakeButton(txtUpdate),
- Child, printButton = MakeButton(txtPrint),
- Child, closeButton = MakeButton(txtClose),
- Child, frontButton = MakeButton(txtToFront),
- Child, moreButton = MakeButton(txtMore),
- Child, exitButton = MakeButton(txtExit),
- End,
- End,
- TAG_MORE, msg->ops_AttrList))
- {
- struct WindowsWinData *wwd = INST_DATA(cl, obj);
- APTR parent;
-
- wwd->wwd_WindowTree = wintree;
- wwd->wwd_WindowText = wintext;
- wwd->wwd_CloseButton = closeButton;
- wwd->wwd_FrontButton = frontButton;
- wwd->wwd_MoreButton = moreButton;
-
- parent = (APTR)GetTagData(MUIA_Window_ParentWindow, (ULONG)NULL, msg->ops_AttrList);
-
- set(obj, MUIA_Window_Title, MyGetWindowTitle("SCREENS & WINDOWS", wwd->wwd_Title, sizeof(wwd->wwd_Title)));
- set(obj, MUIA_Window_ActiveObject, winlist);
- set(moreButton, MUIA_Disabled, TRUE);
-
- DoMethod(parent, MUIM_Window_AddChildWindow, obj);
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, parent, 2, MUIM_Window_RemChildWindow, obj);
- DoMethod(wintree, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime, obj, 1, MUIM_WindowsWin_ListChange);
- DoMethod(wintree, MUIM_Notify, MUIA_NListtree_DoubleClick, MUIV_EveryTime, obj, 1, MUIM_WindowsWin_More);
- DoMethod(updateButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_WindowsWin_Update);
- DoMethod(printButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_WindowsWin_Print);
- DoMethod(closeButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_WindowsWin_Close);
- DoMethod(frontButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_WindowsWin_ToFront);
- DoMethod(moreButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_WindowsWin_More);
- DoMethod(exitButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 3, MUIM_Set, MUIA_Window_CloseRequest, TRUE);
- }
-
- return (ULONG)obj;
- }
-
- static ULONG __saveds mDispose( struct IClass *cl,
- Object *obj,
- struct opSet *msg )
- {
- struct WindowsWinData *wwd = INST_DATA(cl, obj);
-
- set(obj, MUIA_Window_Open, FALSE);
- DoMethod(wwd->wwd_WindowTree, MUIM_NListtree_Clear, NULL, 0);
-
- return (DoSuperMethodA(cl, obj, msg));
- }
-
- static ULONG __saveds mUpdate( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct WindowsWinData *wwd = INST_DATA(cl, obj);
- struct WindowsCallbackUserData ud;
-
- ApplicationSleep(TRUE);
- set(wwd->wwd_WindowTree, MUIA_NListtree_Quiet, TRUE);
- DoMethod(wwd->wwd_WindowTree, MUIM_NListtree_Clear, NULL, 0);
-
- ud.ud_Tree = wwd->wwd_WindowTree;
- ud.ud_Count = 0;
-
- if (clientstate) {
- ReceiveList(UpdateCallback, &ud);
- } else {
- IterateList(UpdateCallback, &ud);
- }
-
- MySetContents(wwd->wwd_WindowText, "");
-
- set(wwd->wwd_WindowTree, MUIA_NListtree_Quiet, FALSE);
- set(wwd->wwd_WindowTree, MUIA_NListtree_Active, MUIV_NListtree_Active_Off);
- set(wwd->wwd_CloseButton, MUIA_Disabled, TRUE);
- set(wwd->wwd_FrontButton, MUIA_Disabled, TRUE);
- set(wwd->wwd_MoreButton, MUIA_Disabled, TRUE);
- ApplicationSleep(FALSE);
-
- return 0;
- }
-
- static ULONG __saveds mPrint( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- PrintWindows(NULL);
-
- return 0;
- }
-
- static ULONG __saveds mClose( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct WindowsWinData *wwd = INST_DATA(cl, obj);
- struct MUI_NListtree_TreeNode *tn;
-
- if (tn = GetActiveTreeNode(wwd->wwd_WindowTree)) {
- struct WindowEntry *we = (struct WindowEntry *)tn->tn_User;
-
- if (stricmp(we->we_Type, "SCREEN") == 0) {
- if (MyRequest(msgYesNo, msgWantToCloseScreen, we->we_Title)) {
- MyDoCommand("CloseScreen %s", we->we_Address);
- DoMethod(obj, MUIM_WindowsWin_Update);
- }
- } else if (stricmp(we->we_Type, "WINDOW") == 0) {
- if (MyRequest(msgYesNo, msgWantToCloseWindow, we->we_Title)) {
- MyDoCommand("CloseWindow %s", we->we_Address);
- DoMethod(obj, MUIM_WindowsWin_Update);
- }
- }
- }
-
- return 0;
- }
-
- static ULONG __saveds mToFront( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct WindowsWinData *wwd = INST_DATA(cl, obj);
- struct MUI_NListtree_TreeNode *tn;
-
- if (tn = GetActiveTreeNode(wwd->wwd_WindowTree)) {
- struct WindowEntry *we = (struct WindowEntry *)tn->tn_User;
-
- MyDoCommand("PopToFront %s", we->we_Address);
- }
-
- return 0;
- }
-
- static ULONG __saveds mMore( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct WindowsWinData *wwd = INST_DATA(cl, obj);
- struct MUI_NListtree_TreeNode *tn;
-
- if (tn = GetActiveTreeNode(wwd->wwd_WindowTree)) {
- struct WindowEntry *we = (struct WindowEntry *)tn->tn_User;
- APTR detailWin;
-
- if (detailWin = WindowsDetailWindowObject,
- MUIA_Window_Title, we->we_Title,
- MUIA_Window_ParentWindow, obj,
- MUIA_Window_MaxChildWindowCount, (opts.SingleWindows) ? 1 : 0,
- End) {
- set(detailWin, MUIA_WindowsDetailWin_Object, we);
- set(detailWin, MUIA_Window_Open, TRUE);
- }
- }
-
- return 0;
- }
-
- static ULONG __saveds mListChange( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct WindowsWinData *wwd = INST_DATA(cl, obj);
- struct MUI_NListtree_TreeNode *tn;
-
- if (tn = GetActiveTreeNode(wwd->wwd_WindowTree)) {
- struct WindowEntry *we = (struct WindowEntry *)tn->tn_User;
-
- MySetContents(wwd->wwd_WindowText, "%s \"%s\"", we->we_Address, we->we_Title);
- set(wwd->wwd_CloseButton, MUIA_Disabled, FALSE);
- set(wwd->wwd_FrontButton, MUIA_Disabled, FALSE);
- if (!clientstate) set(wwd->wwd_MoreButton, MUIA_Disabled, FALSE);
- }
-
- return 0;
- }
-
- ULONG __asm __saveds WindowsWinDispatcher( register __a0 struct IClass *cl,
- register __a2 Object *obj,
- register __a1 Msg msg )
- {
- switch (msg->MethodID) {
- case OM_NEW: return (mNew(cl, obj, (APTR)msg));
- case OM_DISPOSE: return (mDispose(cl, obj, (APTR)msg));
- case MUIM_WindowsWin_Update: return (mUpdate(cl, obj, (APTR)msg));
- case MUIM_WindowsWin_Print: return (mPrint(cl, obj, (APTR)msg));
- case MUIM_WindowsWin_Close: return (mClose(cl, obj, (APTR)msg));
- case MUIM_WindowsWin_ToFront: return (mToFront(cl, obj, (APTR)msg));
- case MUIM_WindowsWin_More: return (mMore(cl, obj, (APTR)msg));
- case MUIM_WindowsWin_ListChange: return (mListChange(cl, obj, (APTR)msg));
- }
-
- return (DoSuperMethodA(cl, obj, msg));
- }
-
- void PrintWindows( char *filename )
- {
- BPTR handle;
-
- if (handle = HandlePrintStart(filename)) {
- PrintFOneLine(handle, "\n Address Pos(x,y) Size(x,y) Flags IDCMP Title\n\n");
- IterateList(PrintCallback, (void *)handle);
- }
-
- HandlePrintStop();
- }
-
- void SendWinList( void )
- {
- IterateList(SendCallback, NULL);
- }
-
-